/**
 * Copyright [2020] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.gateway.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.RequestParameterBuilder;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.schema.ScalarType;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.ParameterType;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.Collections;

/**
 * @project-name:gateway
 * @package-name:com.hyts.gateway.web.config
 * @author:LiBo/Alex
 * @create-date:2020-12-29 20:13
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
@EnableOpenApi
@Configuration
public class SwaggerConfiguration {

    /**
     * swagger 信息
     * @return 页面信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("FSM状态机服务API")
                .description("FSM状态流转服务接口文档")
                .termsOfServiceUrl("https://gitee.com/osscd/coffice-fsm")
                .version("1.0.0")
                .contact(new Contact("李博", "https://www.cnblogs.com/liboware",
                        "liboware@gmail.com")).build();
    }

    @Bean
    public Docket customImplementation() {
//        ParameterBuilder builder = new ParameterBuilder();
//        Parameter parameter = builder
//                //参数类型支持header, cookie, body, query etc
//                .parameterType("header")
//                //参数名
//                .name("Token")
//                .description("请输入您的Token")
//                //指定参数值的类型
//                .modelRef(new ModelRef("string"))
//                .required(false)
//                .build();
//        List<Parameter> parameters = Lists.newArrayList(parameter);
        RequestParameterBuilder parameterBuilder = new RequestParameterBuilder().
                in(ParameterType.HEADER).name("Token").required(false).
                query(param -> param.model(model -> model.scalarModel(ScalarType.STRING)));
        return new Docket(DocumentationType.OAS_30)
                // TODO: 2017/11/2 等等待配置域名
                //.host()
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hyts.fsm.admin"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(this.apiInfo())
                .globalRequestParameters(Collections.singletonList(parameterBuilder.build()));
    }
}
